<?php

/**
 * listing_content actions.
 *
 * @package    master_directory
 * @subpackage listing_content
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class listing_contentActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
  	$this->listing = Doctrine_Core::getTable ( 'Listing' )->find(array($request->getParameter("list_id"))) ;
  	
  	$this->list_field = ($request->getParameter("field_id") != null) ? Doctrine_Core::getTable ( 'ListField' )->find(array($request->getParameter("field_id"))) : new ListField();
  	
  	$this->fields = $this->listing->getListField() != null ? $this->listing->getListField()  : array();
  	
  }
  
  public function executeCreate(sfWebRequest $request)
  {
  	$listing_id = $request->getParameter("listing_id");
  	$field = new ListField();
  	$field->setFieldTypeId(1);
  	$field->setListingId($listing_id);
  	$field->setName($request->getParameter("list_field_name"));
  	$field->setValue($request->getParameter("field_value"));
  	$field->save();
  	
  	$index_url = 'listing_content/index?list_id='.$listing_id;
  	
  	return $this->redirect($index_url);
  	
  }
  
public function executeUpdate(sfWebRequest $request)
  {
  	$listing_id = $request->getParameter("listing_id");
  	$field = Doctrine_Core::getTable ( 'ListField' )->find(array($request->getParameter("field_id")));
  	$field->setFieldTypeId(1);
  	$field->setListingId($listing_id);
  	$field->setName($request->getParameter("list_field_name"));
  	$field->setValue($request->getParameter("field_value"));
  	$field->save();
  	
  	$index_url = 'listing_content/index?list_id='.$listing_id;
  	
  	return $this->redirect($index_url);
  	
  }
  
  public function executeDelete(sfWebRequest $request){
  	
  	$listing_id = $request->getParameter("listing_id");
  	
  	$field_id = $request->getParameter("field_id");
  	
  	$field = Doctrine_Core::getTable ( 'ListField' )->find($field_id) ;
  	
  	$field->delete();
  	
  	$index_url = 'listing_content/index?list_id='.$listing_id;
  	
  	return $this->redirect($index_url);
  	
  }
  
}
